package com.xuan.shop.config;

import com.xuan.shop.quartz.updateUsername;
import org.quartz.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 定时器
 */
@Configuration
public class MyQuartzConfig {

    @Bean
    public JobDetail jobDetail(){
        return JobBuilder
                .newJob(updateUsername.class)
                .withIdentity("updateUsername-id")//唯一名称
                .storeDurably(true)//一直执行
                .build();
    }

    @Bean
    public Trigger jobTrigger(){
        return TriggerBuilder
                .newTrigger()
                .forJob(jobDetail())
                .withIdentity("updateUsername-id")
                .withSchedule(CronScheduleBuilder.cronSchedule("0 0 3 * * ? *"))//定义时间的格式每日3点启动
                .build();
    }
}
